package com.lanyou.cook.entity.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lanyou.cook.common.DefaultDateJsonSerializer;
import com.lanyou.cook.datadictionary.InterfaceOperation;
import com.lanyou.cook.service.DataDictionaryService;

@Entity
@EntityListeners({ AuditingEntityListener.class })
@Table(name = " T_COOK_BU_FIELD_JOB_HIS")
public class InterfaceVersionHistory {

	private String id;
	// 领域作业表ID
	private String systemInterfaceId;
	// 领域系统ID
	private String systemId;
	// 领域名称
	private String fieldName;
	// 领域系统名称
	private String fieldSystemName;
	// 接口名称
	private String interfaceName;
	// kettle表主键
	private long kettleJobId;
	// 版本改变是否来源于Kettle
	private Boolean changeFromKettle;
	// 版本
	private int version;
	// 操作
	private String operation;
	// 操作账号
	private String operator;
	// 操作时间
	private Date operatorTime;
	// 接口发送发
	private String senderFieldSystem;
	// 接口接收方
	private String receiverFieldSystem;
	// 发送方数据库类型
	private String senderDBType;
	// 接收方数据库类型
	private String receiverDBType;
	// 接口场景
	private String interfaceScene;
	// 接口简介
	private String interfaceDesc;
	// 技术标准
	private String tecStandard;

	private String creator;

	private String modifier;

	private Date createTime;

	private Date modifyTime;

	@Column(name = "R_JOB_ID")
	public long getKettleJobId() {
		return kettleJobId;
	}

	public void setKettleJobId(long kettleJobId) {
		this.kettleJobId = kettleJobId;
	}

	@Column(name = "TECH_STANDARD_INFO", length = 100)
	public String getTecStandard() {
		return tecStandard;
	}

	public void setTecStandard(String tecStandard) {
		this.tecStandard = tecStandard;
	}

	@Column(name = "SENDER_DB_TYPE_NAME", length = 100)
	public String getSenderDBType() {
		return senderDBType;
	}

	public void setSenderDBType(String senderDBType) {
		this.senderDBType = senderDBType;
	}

	@Column(name = "RECEIVER_DB_TYPE_NAME", length = 100)
	public String getReceiverDBType() {
		return receiverDBType;
	}

	public void setReceiverDBType(String receiverDBType) {
		this.receiverDBType = receiverDBType;
	}

	@Column(name = "INTERFACE_SCENE_INFO", length = 100)
	public String getInterfaceScene() {
		return interfaceScene;
	}

	public void setInterfaceScene(String interfaceScene) {
		this.interfaceScene = interfaceScene;
	}

	@Column(name = "INTERFACE_DESC", length = 100)
	public String getInterfaceDesc() {
		return interfaceDesc;
	}

	public void setInterfaceDesc(String interfaceDesc) {
		this.interfaceDesc = interfaceDesc;
	}

	@Column(name = "KETTLE_DATA_CHANGE")
	public Boolean getChangeFromKettle() {
		return changeFromKettle;
	}

	public void setChangeFromKettle(Boolean changeFromKettle) {
		this.changeFromKettle = changeFromKettle;
	}

	@Column(name = "FIELD_JOB_ID")
	public String getSystemInterfaceId() {
		return systemInterfaceId;
	}

	public void setSystemInterfaceId(String systemInterfaceId) {
		this.systemInterfaceId = systemInterfaceId;
	}

	@Column(name = "JOB_NAME", length = 50)
	public String getInterfaceName() {
		return interfaceName;
	}

	public void setInterfaceName(String interfaceName) {
		this.interfaceName = interfaceName;
	}

	@Column(name = "FIELD_NAME", length = 50)
	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	@Column(name = "FIELD_SYSTEM_NAME", length = 50)
	public String getFieldSystemName() {
		return fieldSystemName;
	}

	public void setFieldSystemName(String fieldSystemName) {
		this.fieldSystemName = fieldSystemName;
	}

	@Column(name = "IF_SENDER_NAME", length = 100)
	public String getSenderFieldSystem() {
		return senderFieldSystem;
	}

	public void setSenderFieldSystem(String senderFieldSystem) {
		this.senderFieldSystem = senderFieldSystem;
	}

	@Column(name = "IF_RECEIVER_NAME", length = 100)
	public String getReceiverFieldSystem() {
		return receiverFieldSystem;
	}

	public void setReceiverFieldSystem(String receiverFieldSystem) {
		this.receiverFieldSystem = receiverFieldSystem;
	}

	@Column(name = "OPERATION_INFO", length = 50)
	public String getOperation() {
		return operation;
	}

	public void setOperation(String operation) {
		this.operation = operation;
	}

	@Column(name = "OPERATOR", length = 20)
	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	@Column(name = "OPERATE_DATE", updatable = false)
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@CreatedDate
	public Date getOperatorTime() {
		return operatorTime;
	}

	public void setOperatorTime(Date operatorTime) {
		this.operatorTime = operatorTime;
	}

	@Id
	@GeneratedValue(generator = "uuidGenerator")
	@GenericGenerator(name = "uuidGenerator", strategy = "uuid")
	@Column(name = "FIELD_JOB_HIS_ID", length = 36)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "VERSION")
	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	@CreatedBy
	@Column(length = 50, updatable=false)
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@LastModifiedBy
	@Column(length = 50)
	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	@Column(name = "CREATED_DATE", updatable=false)
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@CreatedDate
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "LAST_UPDATED_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@LastModifiedDate
	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	@Column(name = "FIELD_SYSTEM_ID")
	public String getSystemId() {
		return systemId;
	}

	public void setSystemId(String systemId) {
		this.systemId = systemId;
	}

	@Transient
	public String getOperationForDisplay() {
		return DataDictionaryService.getInstance().getValueName(InterfaceOperation.TypeCode, operation);
	}

	@Transient
	public String getOperationTimeForExcel() {
		return getOperatorTime().toString();
	}

	@Transient
	public String getChangeForExcel() {
		return getChangeFromKettle() ? "kettle作业提交" : "cook平台维护";
	}

	@Transient
	public String getChange1ForExcel() {
		return getChangeFromKettle() ? "kettle作业提交" : "cook平台维护";
	}
}
